package cn.mystyle.common.constant;

import com.alibaba.fastjson.JSONObject;

import cn.mystyle.common.bean.BaseBean;
import cn.mystyle.common.bean.BaseResponse;
import cn.mystyle.common.enums.CommonResultCode;

/**
 * json格式返回码
 * @author clark
 */
public class ResultCodeJson
{
    /**
     * 不带数据的返回成功
     * @return JSONObject
     */
    public static JSONObject getSuccess()
    {
        BaseResponse br = new BaseResponse();
        return JSONObject.parseObject(br.toString());
    }
    
    /**
     * 带数据的返回成功
     * @param bb
     * @return JSONObject
     */
    public static JSONObject getSuccess(BaseBean bb)
    {
        JSONObject result = getSuccess();
        
        JSONObject data = JSONObject.parseObject(bb.toString());
        result.put("data", data);
        
        return result;
    }
    
    /**
     * 记录已经存在
     * @return JSONObject
     */
    public static JSONObject get2()
    {
        BaseResponse br = new BaseResponse();
        br.setCode(CommonResultCode.RECORD_ALREADY_EXIST.getCode());
        br.setMsg(CommonResultCode.RECORD_ALREADY_EXIST.getMsg());
        return JSONObject.parseObject(br.toString());
    }
    
    /**
     * 数据状态不正确
     * @return JSONObject
     */
    public static JSONObject get4()
    {
        BaseResponse br = new BaseResponse();
        br.setCode(CommonResultCode.INVALID_DATA_STATUS.getCode());
        br.setMsg(CommonResultCode.INVALID_DATA_STATUS.getMsg());
        return JSONObject.parseObject(br.toString());
    }
    
    /**
     * 未知业务异常
     * @return JSONObject
     */
    public static JSONObject get601()
    {
        BaseResponse br = new BaseResponse();
        br.setCode(CommonResultCode.SERVICE_BUSINESS_601.getCode());
        br.setMsg(CommonResultCode.SERVICE_BUSINESS_601.getMsg());
        return JSONObject.parseObject(br.toString());
    }
    
    /**
     * 请登录
     * @return JSONObject
     */
    public static JSONObject get6011000()
    {
        BaseResponse br = new BaseResponse();
        br.setCode(CommonResultCode.SERVICE_BUSINESS_6011000.getCode());
        br.setMsg(CommonResultCode.SERVICE_BUSINESS_6011000.getMsg());
        return JSONObject.parseObject(br.toString());
    }
    
    /**
     * 用户名或密码不正确
     * @return JSONObject
     */
    public static JSONObject get6011001()
    {
        BaseResponse br = new BaseResponse();
        br.setCode(CommonResultCode.SERVICE_BUSINESS_6011001.getCode());
        br.setMsg(CommonResultCode.SERVICE_BUSINESS_6011001.getMsg());
        return JSONObject.parseObject(br.toString());
    }
    
    /**
     * 服务器内部错误
     * @return JSONObject
     */
    public static JSONObject get500()
    {
        BaseResponse br = new BaseResponse();
        br.setCode(CommonResultCode.SERVER_BUSY_NOW.getCode());
        br.setMsg(CommonResultCode.SERVER_BUSY_NOW.getMsg());
        return JSONObject.parseObject(br.toString());
    }
}
